package com.mapreduce.writable;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

//reduce阶段
public class SalaryTotalReducer extends Reducer<IntWritable,Employee
        ,IntWritable,IntWritable> {

    private IntWritable v4 = new IntWritable();//工资的总和 k4


    @Override
    protected void reduce(IntWritable key, Iterable<Employee> values, Context context) throws IOException, InterruptedException {
        IntWritable k4=key;

        int total =0;
        for (Employee value : values) {
            total+=value.getSal();
        }
        v4.set(total);

        context.write(k4,v4);
    }
}